#include<iostream>
#include<fcntl.h>
#include<sys/mman.h>
#include<unistd.h>
#include<sys/stat.h>

int main()
{
    const char* filename = "example.txt";
    int fd = open(filename, O_RDONLY | O_CREAT);
    if(fd == 1)
    {
        perror("open");
        return 1;
    }
    struct stat sb;
    if(fstat(fd, &sb) == -1)
    {
        perror("fstat");
        close(fd);
        return 1;
    }
    
    void* addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
    if(addr == MAP_FAILED)
    {
        perror("mmap");
        close(fd);
        return 1;
    }

    std::cout << "FILE Content: " << static_cast<char*>(addr) << std::endl;

    if(munmap(addr, sb.st_size) == -1)
    {
        perror("mnumap");
    }
    close(fd);
    return 0;
}